package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.dao.core.AccountLicensePrefixDao;
import com.tbit.uqbike.client.dao.core.AdoptionDao;
import com.tbit.uqbike.client.dao.core.MachineDao;
import com.tbit.uqbike.client.pojo.Adoption;
import com.tbit.uqbike.client.pojo.Machine;
import com.tbit.uqbike.client.service.LeaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @AUTHOR: wei.xing
 * @DATE: 2023-04-19 13:42
 **/
@Service
public class LeaseServiceImpl implements LeaseService {

    @Autowired
    AccountLicensePrefixDao licensePrefixDao;
    @Autowired
    MachineDao machineDao;
    @Autowired
    AdoptionDao adoptionDao;

    @Override
    public String getMachineNO(Integer accountId, String license) {
//        String licensePrefix=licensePrefixDao.getMachineNO(accountId);
//        if (licensePrefix != null){
//            license=licensePrefix+license;
//        }
        Machine machine = machineDao.getByLicense(license);
        if (machine == null) {
            return null;
        }
        return machine.getUserCode();
    }

    @Override
    public void addAdoption(Adoption adoption) {
        adoption.setCreateTime(new Date());
        adoptionDao.addAdoption(adoption);
    }

    @Override
    public String getLicensePrefix(Integer accountId) {
        return licensePrefixDao.getMachineNO(accountId);
    }
}
